package com.yufei.toolinterface.listener;

import it.sauronsoftware.cron4j.TaskExecutor;
import it.sauronsoftware.cron4j.TaskExecutorListener;

import javax.swing.JFrame;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yufei.infoExtractor.listener.AbstractTaskExecutorListener;
import com.yufei.infoExtractor.pfw.entity.Task;
import com.yufei.infoExtractor.task.InfoExtractorCommonTask;
import com.yufei.toolinterface.TaskMPanel;

public class SwingTaskExecutorListener extends AbstractTaskExecutorListener {
	private static Log mLog = LogFactory.getLog(SwingTaskExecutorListener.class);

	private JFrame jframe=null;
	public SwingTaskExecutorListener(JFrame jframe) {
		super();
		this.jframe=jframe;
		// TODO Auto-generated constructor stub
	}
	@Override
	public void completenessValueChanged(TaskExecutor arg0, double arg1) {
		// TODO Auto-generated method stub
        
	}

	@Override
	public void executionPausing(TaskExecutor arg0) {
		// TODO Auto-generated method stub
		  TaskMPanel taskMPanel=(TaskMPanel) jframe;

	      InfoExtractorCommonTask infoExtractorCommonTask=(InfoExtractorCommonTask) arg0.getTask();
	      String taskName=infoExtractorCommonTask.getTask().getTaskName();
	      mLog.info("the task "+taskName+" is requested to be paused!");
	      taskMPanel.getInfoExtractorMI().updateTaskStatus(Task.IS_SUSPENG, infoExtractorCommonTask.getTask().getId());
	      taskMPanel.updateTaskStatusByTaskName(taskName, Task.IS_SUSPENG);
	      //for taskExecutor add taskExecutorListener
	}

	@Override
	public void executionResuming(TaskExecutor arg0) {
		// TODO Auto-generated method stub
		  TaskMPanel taskMPanel=(TaskMPanel) jframe;

	      InfoExtractorCommonTask infoExtractorCommonTask=(InfoExtractorCommonTask) arg0.getTask();
	      String taskName=infoExtractorCommonTask.getTask().getTaskName();
	      mLog.info("the task "+taskName+" is requested to be resumed!");
	      taskMPanel.getInfoExtractorMI().updateTaskStatus(Task.IS_RUNNING, infoExtractorCommonTask.getTask().getId());
	      taskMPanel.updateTaskStatusByTaskName(taskName, Task.IS_RUNNING);
	}

	@Override
	public void executionStopping(TaskExecutor arg0) {
		// TODO Auto-generated method stub
		 TaskMPanel taskMPanel=(TaskMPanel) jframe;

	      InfoExtractorCommonTask infoExtractorCommonTask=(InfoExtractorCommonTask) arg0.getTask();
	      String taskName=infoExtractorCommonTask.getTask().getTaskName();
	      mLog.info("the task "+taskName+" is requested to be stoped!");
	      taskMPanel.getInfoExtractorMI().updateTaskStatus(Task.IS_STOPED, infoExtractorCommonTask.getTask().getId());
	      taskMPanel.updateTaskStatusByTaskName(taskName, Task.IS_STOPED);
	}

	@Override
	public void executionTerminated(TaskExecutor arg0, Throwable arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void statusMessageChanged(TaskExecutor arg0, String arg1) {
		// TODO Auto-generated method stub
        
	}
}
